package hwOne1;

import edu.princeton.cs.algs4.StdOut;

/**
 * 作业 1.1.25
 */
public class CalcGcd {
    public static void main(String[] args) {
        // 检查是否有传递参数
        if (args.length == 0) {
            System.out.println("没有传递任何参数！");
            return;
        }
        int n1 = Integer.parseInt(args[0]);
        int n2 = Integer.parseInt(args[1]);
        StdOut.printf("参数1:" + n1 + "参数2:" + n2 + "\n");
        int result = gcd(n1, n2);
        StdOut.printf("r:" + result);
    }
    public static int gcd(int a, int b) {
        if (a == 0) {
            return b;
        }
        if (b == 0) {
            return a;
        }
        if (a > b) {
            int res = a % b;
            return gcd(b, res);
        } else {
            int res = b % a;
            return gcd(a, res);
        }
    }
}
